// SINGULARITY HTML5 GAME ENGINE
// -----------------------------
// Copyright(c) 2013 by Codenova.pl

define(['./Button', '../Core'], function (Button, Core) {
    var RoundedButton = function(objButton, objRoundedButton) {
        // Inherit properties
        Core.InheritProperties(Button(objButton), this);

        this.CornerRadius = objRoundedButton.CornerRadius;
    };

    RoundedButton.prototype = {
        constructor: RoundedButton,

        /**
         * Adds rounded button to the canvas
         * @param ctx
         * @param objHovered
         * @constructor
         */
        Add: function(ctx, objHovered) {
            var textX, textY;

            if(typeof objHovered === "undefined") {
                textX = this.X + ctx.measureText(this.Label).width + (this.Width - ctx.measureText(this.Label).width) / 2;
                textY = this.Y + (this.Height - parseInt(this.LabelSize, 10)) / 2 - 1;
                Core.DrawRoundedRectangleWithText(ctx, this.X, this.Y, this.Width, this.Height, this.BackgroundColor, this.CornerRadius, this.Label, textX, textY, this.LabelColor, this.LabelSize, this.LabelFont, 'right');
            } else {
                textX = objHovered.X + ctx.measureText(objHovered.Label).width + (objHovered.Width - ctx.measureText(objHovered.Label).width) / 2;
                textY = objHovered.Y + (objHovered.Height - parseInt(objHovered.LabelSize, 10)) / 2 - 1;
                Core.DrawRoundedRectangleWithText(ctx, objHovered.X, objHovered.Y, objHovered.Width, objHovered.Height, objHovered.BackgroundColor, this.CornerRadius, objHovered.Label, textX, textY, objHovered.LabelColor, objHovered.LabelSize, objHovered.LabelFont, 'right');
            }
        },

        Create: function(objButton, objRoundedButton) {
            "use strict";
            return new RoundedButton(objButton, objRoundedButton);
        }
    };

    return RoundedButton.prototype.Create;
});